package com.sin.java.tool.httpman.model;

import java.util.ArrayList;
import java.util.List;

public class Pack extends Node {
	private String name;
	private List<Node> nodes = new ArrayList<Node>();

	public Pack() {
		super(TYPE_PACK);
	}

	public Pack(String name) {
		this();
		this.name = name;
	}

	public void addNode(Node node) {
		nodes.add(node);
	}

	public List<Node> getNodes() {
		return this.nodes;
	}

	@Override
	public String toString() {
		return "Pack [name=" + name + ", nodes=" + nodes + "]";
	}

	private static final int C_TAB = '\t';
	private static final int T_NOTE = -1;
	private static final int T_CMD = -2;

	// private static int T_CMD = -2;

	public Pack(List<String> lines, int start, int level) {
		this();

		for (int ix = start; ix < lines.size(); ++ix) {
			String l = lines.get(ix);
			int i;
			for (i = 0; i < l.length(); ++i) {
				char c = l.charAt(i);
				if (c == C_TAB) {
					continue;
				}
				else if (c == '#')
					i = T_NOTE;
				else if (c == '!')
					i = T_CMD;
				break;
			}
			if (i < l.length()) {
				switch (i) {
				case T_NOTE:
					
					break;
				case T_CMD:
					
					break;
				default:
					if(i==level)
						this.name = l.trim();
					else if(i>level)
						this.addNode(new Pack(lines, ix, i));
					break;
				}
			}
			// else // Empty Line
		}

	}

}
